<?php
/**
 * 广告控制器
 * @author maniac

 */

namespace app\manage\controller;



use app\common\model\AdCategory;
use app\facade\Forms;
use app\common\service\Fields;


class Ads extends Base
{
    /**
     * 首页补充
     * @param array $data 列表信息
     */
    public function indexAttach($data)
    {
        $this->categories();
    }
    
    /**
     * 添加/编辑补充
     * @param array $info 信息
     */
    public function addAttach($info)
    {
        $fields = Fields::rows([['f', 'eq', 'place']], 'id,fname');
        $enter  = [];
        $fname  = [];
        foreach ($fields as $field) {
            $enter[] = $field['id'];
            $fname[$field['id']] = $field['fname'];
        }
        $html = Forms::generateHtmls('place', $info, $enter, [], $fname,'f');
        $this->assign('html', $html);


        $this->categories();
    }
    
    /**
     * where 查询条件
     * @return [type] [description]
     */
    public function where()
    {
        $category_id = input('get.category_id/d', 0);
        $where = '';
        if ($category_id) {
            $where = [
                'category_id' => $category_id,
            ];
        }
        return $where;
    }
    
    /**
     * 获取所有广告分类
     */
    private function categories()
    {
        $categories = AdCategory::field('id,name')->order('id ASC')->select();
        $this->assign('categories', $categories);
    }
}
